package com.lft.stack;

import java.util.Scanner;

public class ArrayStackDemo {
	public static void main(String[] args) {
		
		ArrayStack stack = new ArrayStack(5);
		String key;
		boolean loop = true;
		Scanner scanner = new Scanner(System.in);
		
		while (loop) {
			System.out.println("show：表示显示栈");
			System.out.println("exit：表示退出程序");
			System.out.println("push：表示添加数据到栈（入栈）");
			System.out.println("pop：表示从栈中取出数据（出栈）");
			System.out.print("请输入你的选择：");
			key = scanner.next();
			switch (key) {
				case "show":
					stack.show();
					break;
				case "push":
					System.out.print("请输入一个数：");
					stack.push(scanner.nextInt());
					break;
				case "pop":
					try {
						System.out.printf("出栈的数据是 %d\n", stack.pop());
					} catch (Exception e) {
						System.out.println(e.getMessage());
					}
					break;
				case "exit":
					scanner.close();
					loop = false;
					break;
				default:
					break;
			}
		}
		System.out.println("程序退出");
		
	}
}
